// Custom JS to try to update the google_page_url with a better URL
function getParam ( sname )
{
  var tag_iframe_URL = window.location.href;
  var sval = "";
  if (tag_iframe_URL && tag_iframe_URL.indexOf("?") > 0) {
    var params = tag_iframe_URL.substr(tag_iframe_URL.indexOf("?")+1);
    if (params) {
      params = params.split("&");
        // split param and value into individual pieces
        for (var i=0; i<params.length; i++)
         {
           temp = params[i].split("=");
           if ( [temp[0]] == sname ) { sval = temp[1]; }
         }
    }
  }
  return sval;
}
function decod(s) {
 if(typeof decodeURIComponent == 'function') return decodeURIComponent(s);
 else return unescape(s);
}
if (window.location != window.parent.location) {
  // we are running in an iframe
  var iframeloc = window.location.href;
  if (iframeloc) {
     if (iframeloc.indexOf('.doubleclick.net/') > 0 && iframeloc.indexOf(';dc_ref=') > 0) {
        // Running in DFP iframe
        var page_url = iframeloc.substring(iframeloc.indexOf(';dc_ref=') + 8);
        if (page_url && page_url.indexOf(';') > 0) {
           page_url = page_url.substring(0,page_url.indexOf(';'));
        }
        if (page_url) {
           google_page_url = decod(page_url);
        }
     } else {
        if (iframeloc.indexOf('.admeld.com/') > 0) {
           // Running in Admeld iframe, try getting the cf2 parameter from frame URL
           var url_from_iframe = getParam('cf2');
           if (url_from_iframe) {
              google_page_url = decod(url_from_iframe);
           } else {
              // try getting the url parameter from iframe url, for instance for Admeld iframe
              url_from_iframe = getParam('url');
              if (url_from_iframe) {
                 google_page_url = decod(url_from_iframe);
              }
           }
        } else {
           // try getting the url parameter from iframe url, for instance for Admeld iframe
           var url_from_iframe = getParam('url');
           if (url_from_iframe) {
              google_page_url = decod(url_from_iframe);
           } else {
              // fallback to hardcoded
           }
        }
     }
  }
} else {
  // get location from page:
  if (window.location.href) {
    google_page_url = window.location.href;
  }
}

